function ajaxGet(url,params,callback) {//封装ajax get请求模板代码
    //1.create xhr and set onreadystate change
    let xhr=createXHR(callback);
    //3.open connection
    xhr.open("GET",`${url}/${params}`,true);
    //4.send request
    xhr.send();
}
function ajaxPost(url,params,callback) {//封装ajax get请求模板代码
    //1.create xhr and set onreadystate change
    let xhr=createXHR(callback);
    //3.open connection
    xhr.open("POST",url,true);
    //
    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    //4.send request
    xhr.send(params);
}

function createXHR(callback) {
    //1.create XHR object
    let xhr=new XMLHttpRequest();
    xhr.onreadystatechange=function () {
        if(xhr.readyState==4){
            if (xhr.status==200){
                callback(xhr.responseText);
            }
        }
    }
    return xhr;
}